<template>
    <div style="height: 100%; width: 100%; position: relative">
        <div class="pagetop">
            <div class="search-title">
                <table class="table1style">
                    <tr>
                        <td align="right">目标医院</td>
                        <td>
                            <rm-ddl-common datatype="hospital" dataname="医院" @change="hospChange" v-model="txthospcode" isadmincanall="2" width="250px" key="0"></rm-ddl-common>
                        </td>
                        <td>交接人</td>
                        <td>
                            <rm-ddl-common datatype="userinfo" dataname="交接人" @change="senduserChange" v-model="txtuserinfo" width="160px" key="1"></rm-ddl-common>
                        </td>
                        <td>{{ outusername }}</td>
                    </tr>
                    <tr>
                        <td style="font-weight: bold; font-size: 17px">条码扫描</td>
                        <td colspan="3">
                            <el-input v-model="txtbarcode" @keyup.enter.native="InitPage" id="barcode_id" @focus="HightlightPos(txtbarcode)" size="medium" clearable ref="refbarcode" placeholder="请扫描或输入条码……"></el-input>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="top-deal">
                <el-button icon="el-icon-document" @click="btnSave">保存</el-button>
                <el-button icon="el-icon-close" @click="btnClear">清除</el-button>
                <el-button icon="el-icon-printer" @click="btnPrint" :disabled="!islogin">打印</el-button>
                <el-button icon="el-icon-upload2" @click="btnExport">导出</el-button>
            </div>
        </div>
        <div class="pagecenter">
            <rm-layout-right splitcolor="#F8F8FF" movingcolor="#00ff00" :splitwidth="5" :fixsize="400">
                <template v-slot:fix>
                    <div style="height: 100%">
                        <vxe-table show-overflow ref="xTable2" height="auto" :loading="xTable2loading" :select-config="{ reserve: true }" :cell-class-name="cellClassName" :sort-config="{ trigger: 'cell' }" :mouse-config="{ selected: true }" :data.sync="tableData2" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe>
                            <vxe-table-column type="index" title="NO." width="45" align="center"></vxe-table-column>
                            <vxe-table-column field="req_itemname" title="项目名称" width="140" sortable header-align="center"></vxe-table-column>
                            <vxe-table-column field="item_price" title="实际价格" width="75" sortable header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="qty" title="数量" width="50" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="amount" title="金额" width="60" header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="req_itemcode" title="项目代码" width="70" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_itemcode" title="HIS项目代码" width="90" header-align="center"> </vxe-table-column>
                            <vxe-table-column field="his_recordid" title="HIS记录号" width="90" header-align="center"> </vxe-table-column>
                            <vxe-table-column field="combitemna" title="所属组合" width="70" header-align="center"> </vxe-table-column>
                            <vxe-table-column field="base_price" title="基础价格" width="70" header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="stat_flag" title="统计标记" width="70" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="other_flag" title="其他标记" width="70" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="status" title="状态" width="80" header-align="center"></vxe-table-column>
                            <!-- <vxe-table-column field="reportid" title="报告单元ID" width="90" header-align="center"></vxe-table-column> -->
                            <vxe-table-column field="lab_add" title="实验室新增" width="90" header-align="center"></vxe-table-column>
                            <vxe-table-column field="add_dt" title="新增时间" width="120" header-align="center"></vxe-table-column>
                            <vxe-table-column field="add_user" title="新增人" width="90" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="req_groupname" title="分单类别" width="100" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="charge_flag" title="计价标志" width="90px" header-align="center"> </vxe-table-column>
                            <vxe-table-column field="his_refcol1" title="HIS_Refcol1" width="100" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_refcol2" title="HIS_Refcol2" width="100" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_refcol3" title="HIS_Refcol3" width="100" header-align="center"></vxe-table-column>
                            <vxe-table-column field="barcode" title="预设标本号" width="110" header-align="center"></vxe-table-column>
                            <vxe-table-column field="reportid" title="上机报告ID" width="90" header-align="center"></vxe-table-column>
                        </vxe-table>
                    </div>
                </template>
                <div style="height: 100%; width: 100%; background-color: #ddccbb">
                    <vxe-table ref="xTable1" :data.sync="tableData1" show-overflow height="auto" :loading="xTable1loading" :select-config="{ reserve: true }" :cell-class-name="cellClassName" :sort-config="{ trigger: 'cell' }" :keyboard-config="keyConfig" @current-change="currentChangeEvent" :keyboard-local-config="keyLocalConfig" :mouse-config="{ selected: true }" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe @cell-dblclick="DblEvent">
                        <vxe-table-column width="50" field="ischk" title="选择" header-align="center" align="center">
                            <template v-slot="{ row }">
                                <el-checkbox true-label="1" false-label="0" v-model="row.ischk"></el-checkbox>
                            </template>
                        </vxe-table-column>
                        <vxe-table-column field="req_groupname" title="分单类别" width="100" sortable header-align="center"></vxe-table-column>
                        <vxe-table-column field="specimen_name" title="标本类型" width="88" sortable header-align="center" align="center"></vxe-table-column>
                        <vxe-table-column field="req_deptname" title="申请科室" width="80" header-align="center" align="center"></vxe-table-column>
                        <vxe-table-column field="req_bedno" title="床号" width="60" header-align="center" align="center"></vxe-table-column>
                        <vxe-table-column field="pat_name" title="姓名" width="70" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_sex" title="性别" width="60" header-align="center" align="center"> </vxe-table-column>
                        <vxe-table-column field="barcode" title="条码号" width="110" header-align="center"> </vxe-table-column>
                        <vxe-table-column field="emer_flag" title="加急" width="60" header-align="center" align="center"> </vxe-table-column>
                        <vxe-table-column field="sample_items" title="申请项目(简称，部分)" width="140" header-align="center" align="center"></vxe-table-column>
                        <!-- <vxe-table-column field="cp_sendinfo" title="送出信息" width="120" header-align="center" align="center"></vxe-table-column> -->
                        <vxe-table-column field="req_stat" title="状态" width="80" header-align="center"></vxe-table-column>
                        <vxe-table-column field="base_amount" title="应收金额" width="80px"></vxe-table-column>
                        <vxe-table-column field="recieve_dt" title="接收时间" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="recieve_user" title="接收人" width="70" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_no" title="病历号" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_docname" title="申请医生" width="90" header-align="center" align="center"></vxe-table-column>
                        <vxe-table-column field="pat_typecode" title="病人来源" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="create_dt" title="创建时间" width="100" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="create_user" title="创建人" width="90" header-align="center"> </vxe-table-column>
                        <vxe-table-column field="reject_user" title="踢回人" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="reject_dt" title="踢回时间" width="120px" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"> </vxe-table-column>
                        <vxe-table-column field="print_dt" title="打印/执行时间" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="reject_reason" title="踢回原因" width="130" header-align="center"></vxe-table-column>
                        <vxe-table-column field="print_user" title="打印/执行人" width="100" header-align="center"></vxe-table-column>
                        <vxe-table-column field="print_count" title="打印次数" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="sampled_dt" title="采样时间" width="100" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="sampled_user" title="采样人" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="req_dt" title="申请时间" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="pat_diag" title="临床诊断" width="130" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_ageyear" title="年龄" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="pat_id" title="病人ID号" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="inp_date" title="入院日期" width="120" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="send_dt" title="送出时间" width="100" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="send_user" title="送出人" width="90" header-align="center"></vxe-table-column>
                        <vxe-table-column field="charge_dt" title="计价时间" width="120px" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="charge_username" title="计价人" width="70px"></vxe-table-column>
                        <vxe-table-column field="amount" title="实收金额" width="70px"></vxe-table-column>
                        <vxe-table-column field="charge_flag" title="计价标志" width="50px"></vxe-table-column>
                        <vxe-table-column field="test_dt" title="上机时间" width="120px" sortable :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="test_username" title="上机人" width="70px"></vxe-table-column>
                        <vxe-table-column field="report_dt" title="报告时间" width="120" sortable :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="report_username" title="检验医生姓名" width="70px"></vxe-table-column>
                        <vxe-table-column field="rechk_username" title="核对医生姓名" width="70px"></vxe-table-column>
                        <vxe-table-column field="alter_flag" title="报警" width="50px"></vxe-table-column>
                        <vxe-table-column field="saleman" title="销售员" width="70px"></vxe-table-column>
                        <vxe-table-column field="pat_cardno" title="就诊卡号" width="110px"></vxe-table-column>
                        <vxe-table-column field="req_comm" title="医生备注" width="150px"></vxe-table-column>
                        <vxe-table-column field="pat_ageyear" title="年龄岁数" width="50px"></vxe-table-column>
                        <vxe-table-column field="inp_id" title="住院标识/就诊号" width="100px"></vxe-table-column>
                        <vxe-table-column field="pat_diag_icd" title="诊断标准代码" width="100px"></vxe-table-column>
                        <vxe-table-column field="pat_address" title="地址" width="150px"></vxe-table-column>
                        <vxe-table-column field="pat_nation" title="国籍" width="60px"></vxe-table-column>
                        <vxe-table-column field="pat_idcardno" title="身份证号/护照号" width="150px"></vxe-table-column>
                        <vxe-table-column field="pat_phone" title="联系电话" width="100px"></vxe-table-column>
                        <vxe-table-column field="charge_typename" title="费别" width="100px"></vxe-table-column>
                        <vxe-table-column field="perform_deptname" title="执行科室" width="100px"></vxe-table-column>
                        <vxe-table-column field="req_wardname" title="病区" width="100px"></vxe-table-column>
                        <vxe-table-column field="original_reqno" title="原始申请单号" width="110px"></vxe-table-column>
                        <vxe-table-column field="secrecy" title="加密" width="60px"></vxe-table-column>
                        <vxe-table-column field="other_stat" title="其他状态" width="100px"></vxe-table-column>
                        <vxe-table-column field="cancel_dt" title="作废时间" width="120px" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="cancel_user" title="做废人" width="70px"></vxe-table-column>
                        <vxe-table-column field="reject_count" title="踢回次数" width="70px"></vxe-table-column>
                        <vxe-table-column field="specimen_code" title="标本类型代码" width="100px"></vxe-table-column>
                        <vxe-table-column field="sample_detail" title="标本备注说明" width="130px"></vxe-table-column>
                        <vxe-table-column field="req_reason" title="检验目的" width="100px"></vxe-table-column>
                        <vxe-table-column field="master_barcode" title="主申请单ID" width="70px"></vxe-table-column>
                        <vxe-table-column field="multi_seq" title="子申请单序号" width="70px"></vxe-table-column>
                        <vxe-table-column field="req_groupid" title="分单类别ID" width="70px"></vxe-table-column>
                        <vxe-table-column field="report_id" title="报告单ID" width="70px"></vxe-table-column>
                        <vxe-table-column field="report_user" title="检验医生代码" width="100px"></vxe-table-column>
                        <vxe-table-column field="rechk_user" title="核对医生代码" width="100px"></vxe-table-column>
                        <vxe-table-column field="recieve1_dt" title="工作组签收时间" width="120px" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="recieve1_user" title="工作组签收人" width="120px" :formatter="['toDateString', 'yyyy-MM-dd HH:mm']"></vxe-table-column>
                        <vxe-table-column field="inlib_status" title="入库状态" width="80px"></vxe-table-column>
                        <vxe-table-column field="library_id" title="所在库位ID" width="70px"></vxe-table-column>
                        <vxe-table-column field="reqtype" title="申请单类别" width="60px"></vxe-table-column>
                        <vxe-table-column field="pat_height" title="身高(cm)" width="70px"></vxe-table-column>
                        <vxe-table-column field="weight" title="体重(kg)" width="70px"></vxe-table-column>
                        <vxe-table-column field="abo_bldtype" title="ABO血型" width="100px"></vxe-table-column>
                        <vxe-table-column field="rh_bldtype" title="RH血型" width="100px"></vxe-table-column>
                        <vxe-table-column field="tube_color" title="试管颜色" width="100" header-align="center">
                            <!-- <template v-slot="{row}">
                                <div :style="{background:'#'+row.tube_color}"></div>
                            </template> -->
                        </vxe-table-column>
                        <vxe-table-column field="collectbarcode" title="回单条码号" width="120px"></vxe-table-column>
                        <vxe-table-column field="outscan_dt" title="扫描时间" width="120px" header-align="center"></vxe-table-column>
                    </vxe-table>
                </div>
            </rm-layout-right>
        </div>
        <!--交接人-->
        <el-dialog title="提示" :visible.sync="dialoguserOpen" width="700px">
            <rm-pop-common @change="userinfochange" datatype="userinfo" dataname="用户" width="200px"></rm-pop-common>
        </el-dialog>
        <el-dialog width="700px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" title="申请项目明细" :visible.sync="dialogTableVisible">
            <template>
                <div style="width: 100%; position: relative">
                    <div style="width: 100%">
                        <table style="font-size: 12px; white-space: nowrap; max-width: 1170px">
                            <tr>
                                <td style="width: 650px; text-align: right">
                                    <el-button @click="btnsure()" icon="el-icon-search">确定</el-button>
                                    <!-- <el-button @click="btnHistoryPrint()" icon="el-icon-printer">打印包条码</el-button> -->
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div style="height: 400px; top: 60px; width: 100%">
                        <vxe-table ref="selTable" :data.sync="selecttableData" :loading="selectloading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border fit height="auto" header-align="center" highlight-current-row highlight-hover-row highlight-hover-column resizable show-header-overflow="tooltip" show-overflow="tooltip" size="mini" stripe>
                            <vxe-table-column type="selection" width="40" align="center"></vxe-table-column>
                            <vxe-table-column field="req_itemname" title="项目名称" width="140" sortable header-align="center"></vxe-table-column>
                            <vxe-table-column field="item_price" title="实际价格" width="75" sortable header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="qty" title="数量" width="50" header-align="center" align="center"></vxe-table-column>
                            <vxe-table-column field="amount" title="金额" width="60" header-align="center" align="right"></vxe-table-column>
                            <vxe-table-column field="req_itemcode" title="项目代码" width="70" header-align="center"></vxe-table-column>
                            <vxe-table-column field="his_itemcode" title="HIS项目代码" width="90" header-align="center"> </vxe-table-column>
                            <vxe-table-column field="his_recordid" title="HIS记录号" width="90" header-align="center"></vxe-table-column>
                        </vxe-table>
                    </div>
                </div>
            </template>
        </el-dialog>
    </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
    name: "LIS224",
    data() {
        return {
            xTable2loading: false,
            xTable1loading: false,
            islogin: false,
            tableData1: [],
            tableData2: [],
            txtuserinfo: "", //外送接收人
            txthospcode: "",
            txtbarcode: "",
            outuserno: "", //外送人
            outusername: "",
            barcodes: "",
            outscan_dts: "",
            printer: "",
            reqoutstyleid: "",
            senduser: "",
            userList: [],
            barcodeArr: [],
            dialoguserOpen: false,
            keyConfig: {
                isDel: true,
                isTab: true,
                isEdit: true,
            },
            keyLocalConfig: {
                isArrow: true,
            },
            isallowpartoutsend: "",
            selecttableData: [],
            selectloading: false,
            selbarcode: "",
            dialogTableVisible: false,
            selectrow: "",
            isonlysentoutflagreqitem: "",
            defaulsendhospital: "",
        };
    },
    created() {
        this.InitData();
    },
    mounted() {
        this.$refs.refbarcode.focus();
    },
    updated() {},
    methods: {
        InitPage() {
            if (this.barcodeArr.indexOf(this.txtbarcode) > -1) {
                //如果列表中已经存在了就不再加入列表
                return false;
            }
            if (!this.txthospcode) {
                this.$pub.message(this, "请先选择目标医院！", "error", 1000);
                return false;
            }
            this.xTable1loading = false;
            this.$tool
                .request({
                    url: "LIS/LIS2/LIS224",
                    method: "post",
                    data: {
                        action: "InitPage",
                        barcode: this.txtbarcode,
                        desthospital: this.txthospcode,
                    },
                })
                .then((res) => {
                    if (res.flag == "1") {
                        if (res.Data.length > 0) {
                            if (this.isallowpartoutsend == "1") {
                                this.selectrow = res.Data[0];
                                this.selectrow.outscan_dt = this.$pub.InitDateTime();
                                this.selbarcode = this.selectrow.barcode;
                                this.QueryDetail(this.selectrow.barcode);
                            } else {
                                if (this.isonlysentoutflagreqitem == "1") {
                                    this.selectrow = res.Data[0];
                                    this.selectrow.outscan_dt = this.$pub.InitDateTime();
                                    this.selbarcode = this.selectrow.barcode;
                                    this.QueryDetail(this.selectrow.barcode);
                                } else {
                                    res.Data.forEach((item) => {
                                        item.outscan_dt = this.$pub.InitDateTime();
                                    });

                                    this.$refs.xTable1.insertAt(res.Data, 0).then(({ row }) => {
                                        this.$refs.xTable1.setCurrentRow(row); //高亮行
                                        this.$refs.xTable1.scrollToRow(row); //滚动到行
                                        this.selbarcode = row.barcode;
                                        this.tableData1.push(row);
                                        this.QueryDetail(row.barcode);
                                    });

                                    this.barcodeArr.push(this.txtbarcode);
                                    this.xTable1loading = false;
                                }
                            }
                        } else {
                            this.selbarcode = "";
                            this.txtbarcode = "没有找到条码号对应的数据！";
                        }
                        this.HightlightPos(this.txtbarcode);
                    } else {
                        this.selbarcode = "";
                        this.txtbarcode = res.msg;
                        this.HightlightPos(this.txtbarcode);
                    }
                })
                .catch((e) => {
                    this.xTable1loading = false;
                    this.$message.warning(e);
                });
        },
        async QueryDetail(rowbarcode) {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS224",
                    method: "post",
                    data: {
                        action: "QueryDetail",
                        barcode: rowbarcode,
                    },
                });

                if (this.isallowpartoutsend == "1") {
                    this.selecttableData = res.Data;
                    this.dialogTableVisible = true;
                } else {
                    if (this.isonlysentoutflagreqitem == "1") {
                        let tdata = res.Data.filter((item) => item.out_flag == "1");

                        if (tdata.length == "0") {
                            this.$message.error("该申请单无外送标志的申请项目");
                            return false;
                        }
                        // this.tableData2 = tdata;
                        //this.loadFirstRow(this.$refs.xTable2, "");
                        this.outsentdetail(tdata);
                    } else {
                        this.tableData2 = res.Data;
                        this.loadFirstRow(this.$refs.xTable2, "");
                    }
                }
            } catch (e) {}
        },
        //自动加载表格的第一行，并执行回调函数
        loadFirstRow(xTable, func) {
            this.$nextTick(() => {
                // 加载第一行
                var selectrow = xTable.getData(0);
                if (selectrow) {
                    xTable.setCurrentRow(selectrow); //高亮行
                    xTable.scrollToRow(selectrow); //滚动到行
                    if (typeof func == "function") func(selectrow);
                } else {
                    xTable.setCurrentRow(null); //这个不会自动清空
                }
            });
        },
        hospChange(code, name) {
            this.txthospcode = code;
            //写入缓存
            let jsondate = {
                localsendhospital: this.txthospcode,
                localsenduserid: this.txtuserinfo,
            };
            let modListJson = JSON.stringify(jsondate);
            localStorage.setItem("lis224sendinfo", modListJson);
        },
        senduserChange() {
            //写入缓存
            let jsondate = {
                localsendhospital: this.txthospcode,
                localsenduserid: this.txtuserinfo,
            };
            let modListJson = JSON.stringify(jsondate);
            localStorage.setItem("lis224sendinfo", modListJson);
        },
        btnSave() {
            if (this.txthospcode.trim() == "") {
                this.$alert("请选择目标医院！", "信息", {
                    confirmButtonText: "确定",
                    showClose: false,
                });
                return false;
            }
            if (this.txtuserinfo.trim() == "") {
                this.$alert("请选择交接人！", "信息", {
                    confirmButtonText: "确定",
                    showClose: false,
                });
                return false;
            }

            if (!this.islogin) {
                //未登录过
                this.$rm_Login({
                    type: "用户登录验证",
                    btn: {
                        confirmBtnText: "确定",
                        cancelBtnText: "取消",
                    },
                })
                    .then((res) => {
                        if (res.flag == "1") {
                            //登录成功
                            this.outuserno = res.userid;
                            this.outusername = "送出用户：" + res.username;
                            this.islogin = true;
                            this.confirmSaverecord();
                        }
                        this.autoFocusBarcode();
                    })
                    .catch((e) => {
                        console.log("error", e);
                        this.autoFocusBarcode();
                    });
            } else {
                //登录过
                this.confirmSaverecord();
            }
        },
        async confirmSaverecord() {
            let data = this.$refs.xTable1.tableData;
            let finddata = data.filter((item) => item.ischk == "1");
            if (finddata.length == 0) {
                this.$alert("请选择要保存的数据！", "提示", {
                    confirmButtonText: "确定",
                    showClose: false,
                }).then(() => {
                    this.autoFocusBarcode();
                });
                return false;
            }
            let barcodes = [];
            let outscan_dt = [];
            if (finddata.length > 0) {
                if (this.isallowpartoutsend == "1" || this.isonlysentoutflagreqitem == "1") {
                    finddata.forEach((item) => {
                        barcodes.push(item.barcode + ":" + item.sendoutitems + ":" + item.sendoutitemnames);
                        outscan_dt.push(item.outscan_dt);
                    });
                } else {
                    finddata.forEach((item) => {
                        barcodes.push(item.barcode);
                        outscan_dt.push(item.outscan_dt);
                    });
                }
            } else {
                this.autoFocusBarcode();
                return false;
            }
            this.barcodes = barcodes.join(";");
            this.outscan_dts = outscan_dt.join(",");
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS224",
                    method: "post",
                    data: {
                        action: "save",
                        barcodes: this.barcodes,
                        hospcode: this.txthospcode,
                        getoutuser: this.txtuserinfo,
                        outuserno: this.outuserno,
                        outscan_dts: this.outscan_dts,
                        allowpartoutsend: this.isallowpartoutsend,
                    },
                });
                if (res.Item2 == "OK") {
                    var outids = res.Item4.split(";");

                    finddata.forEach((item) => {
                        item.ischk = "0";
                        item.saveflag = "1"; //保存成功置为1
                        for (let i = 0; i < outids.length; i++) {
                            let element = outids[i];
                            var arr = element.split(":");
                            if (item.barcode == arr[0]) {
                                item.outid = arr[1];
                            }
                        }
                    });
                    this.$alert("保存成功！", "信息", {
                        confirmButtonText: "确定",
                        showClose: false,
                    }).then(() => {
                        this.autoFocusBarcode();
                    });
                } else {
                    this.$alert("保存失败！" + res.Item2, "信息", {
                        confirmButtonText: "确定",
                        showClose: false,
                    }).then(() => {
                        this.autoFocusBarcode();
                    });
                }
            } catch (e) {
                this.$message.warning(e);
                this.autoFocusBarcode();
            }
        },
        // 弹窗确定按钮
        btnsure() {
            let data = this.$refs.selTable.getSelectRecords();
            if (data.length == 0) {
                this.$alert("请勾选要外送的申请项目");
                return;
            }
            this.outsentdetail(data);
        },

        outsentdetail(data) {
            // 拼接要选的申请项目
            var itemcodes = "";
            var itemcodenames = "";
            data.forEach((element) => {
                itemcodes += element.req_itemcode + "-";
                itemcodenames += element.req_itemname + ",";
            });

            try {
                this.selectrow.sendoutitems = itemcodes;
                this.selectrow.sendoutitemnames = itemcodenames.substring(0, itemcodenames.length - 1);
                this.selectrow.sample_items = itemcodenames.substring(0, itemcodenames.length - 1);
                this.$refs.xTable1.insertAt(this.selectrow, 0).then(({ row }) => {
                    this.$refs.xTable1.setCurrentRow(row); //高亮行
                    this.$refs.xTable1.scrollToRow(row); //滚动到行
                    this.selbarcode = row.barcode;
                    this.tableData1.unshift(row);
                });
                this.barcodeArr.unshift(this.txtbarcode);
                this.xTable1loading = false;
                this.tableData2 = data;
                this.dialogTableVisible = false;
            } catch (error) {
                this.dialogTableVisible = false;
            }
        },

        btnClear() {
            this.txtuserinfo = "";
            this.txthospcode = " ";
            this.txtbarcode = "";
            this.tableData1 = [];
            this.tableData2 = [];
            this.autoFocusBarcode();
            this.barcodeArr = [];
        },
        btnExport() {
            let options = {
                filename: "LIS224 标本外送.csv",
            };
            this.$refs.xTable1.exportCsv(options);
        },
        btnPrint() {
            //运送人弹窗未做
            let data = this.$refs.xTable1.tableData;
            let finddata = data.filter((item) => item.saveflag == "1");
            if (finddata.length == 0) {
                this.$message("请勾选打印的数据");
                return false;
            }
            let printbarcodes = "";
            let outids = "";
            finddata.forEach((item) => {
                if (printbarcodes == "") {
                    printbarcodes = item.barcode;
                } else {
                    printbarcodes = printbarcodes + "$" + item.barcode;
                }
                if (outids == "") {
                    outids = item.outid;
                } else {
                    outids = outids + "$" + item.outid;
                }
            });

            var sql = "SP_Print_ReqOut 'barcodes:" + printbarcodes + "','senduser:','outids:" + outids + "'";

            this.$pub.printlistbill(this, sql, 1, this.reqoutstyleid, "外送清单", this.printer);
        },
        cellClassName({ row }) {},
        currentChangeEvent({ row }) {
            if (this.isallowpartoutsend == "1" || this.isonlysentoutflagreqitem == "1") {
                this.QuerySelDetail(row.barcode, row.sendoutitems);
            } else {
                this.QueryDetail(row.barcode);
            }
        },

        async QuerySelDetail(rowbarcode, selitems) {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS224",
                    method: "post",
                    data: {
                        action: "QuerySelDetail",
                        barcode: rowbarcode,
                        selitems: selitems,
                    },
                });
                this.tableData2 = res.Data;
                this.loadFirstRow(this.$refs.xTable2, "");
            } catch (e) {}
        },
        autoFocusBarcode() {
            setTimeout(() => {
                this.FocusBarcode(); //聚焦到条码框
            }, 100);
        },
        FocusBarcode(myField) {
            if (!myField) myField = document.getElementById("barcode_id");
            myField.focus();
            myField.select();
        },
        HightlightPos(myValue) {
            if (myValue == "") {
                return false;
            }
            var myField = document.getElementById("barcode_id");
            if (myField.selectionStart || myField.selectionStart === 0) {
                var startPos = myField.selectionStart;
                var endPos = myField.selectionEnd;
                this.$nextTick(() => {
                    myField.selectionStart = 0;
                    myField.selectionEnd = startPos + myValue.length;
                });
                myField.focus();
                myField.setSelectionRange(myField, myField.selectionStart, myField.selectionEnd);
            }
        },
        async InitData() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS2/LIS224",
                    method: "post",
                    data: {
                        action: "InitData",
                    },
                });
                this.userList = res.userlist;
                this.printer = res.printer;
                this.reqoutstyleid = res.reqoutstyleid;
                this.isallowpartoutsend = res.allowpartoutsend; // 允许部分外送
                this.isonlysentoutflagreqitem = res.isonlysentoutflagreqitem; // 仅外送具有外送标志的申请项目
                this.defaulsendhospital = res.defaulsendhospital; // 默认送出医院
                if (!!this.defaulsendhospital) {
                    this.txthospcode = this.defaulsendhospital;
                }
                //读取缓存，若缓存有，则以缓存为准
                var sendinfo = localStorage.getItem("lis224sendinfo");
                if (sendinfo != null && sendinfo != "") {
                    let jsondate = JSON.parse(sendinfo);
                    this.txthospcode = jsondate.localsendhospital;
                    this.txtuserinfo = jsondate.localsenduserid;
                }
            } catch (e) {
                this.$message.warning(e);
            }
        },
        userinfochange(code, name) {
            this.txtuserinfo = name;
            this.dialoguserOpen = false;
        },

        DblEvent({ row, rowIndex, $rowIndex, column }) {
            this.$confirm("确定移除该条数据【" + row.barcode + "_" + row.pat_name + "_" + row.sample_items + " 】？", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            }).then(() => {
                for (let index = 0; index < this.barcodeArr.length; index++) {
                    const element = this.barcodeArr[index];
                    if (element == row.barcode) {
                        this.barcodeArr.splice(index, 1);
                        break;
                    }
                }

                this.$refs.xTable1.remove(row);
                this.tableData1.splice(rowIndex, 1);
                if (this.tableData1.length == 0) {
                    this.tableData2 = [];
                }
                this.loadFirstRow(this.$refs.xTable1, "");
            });
        },
    },
};
</Script>

<style scoped>
.pagetop {
    width: 100%;
    height: 75px;
    display: -webkit-box;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    border: 1px solid #ccc;
    position: absolute;
    z-index: 99;
}

.pagecenter {
    position: absolute;
    top: 80px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}

.table1style tr td {
    padding: 0px 2px 0px 2px;
}

/deep/ .el-button.is-disabled {
    border: 0px;
    color: grey;
    background-color: #e6e6e6;
    font-weight: normal;
}
.search-title {
    margin: 0 5px 0 20px;
    font-size: 12px;
    top: 3px;
    position: absolute;
}
.top-deal {
    right: 5px;
    position: absolute;
    top: 45px;
    display: flex;
    align-items: center;
}
</style>